﻿//判断是否外协帐号
function isWXAccount(account) {
    var userPref = account.substr(0, 2).toLowerCase();
    var userArr = ["kf", "gw", "fw", "hw", "hp", "wx", "wy", "ds", "se", "ys", "hz", "hy","rt"];
    for (var i = 0; i < userArr.length; i++) {
        if (userArr[i] == userPref) {
            return true;
        }
    }
    return false;
};
//判断是否公共应用系统帐号
function isAppSysAccont(account) {
    var userPref = account.substr(0, 3).toLowerCase();
    var userArr = ["app", "pub"];
    for (var i = 0; i < userArr.length; i++) {
        if (userArr[i] == userPref) {
            return true;
        }
    }
    return false;
};

//是否域账户类型
function isSamAccountType(clostype) {
    var userArr = ["domainaccounttype", "emailtype", "lynctype", "notes", "proxytype", "sslvpn", "ssmp", "scdp", "psd", "kpi", "iplan", "idms", "ise", "crm", "kms", "hrss", "ecn", "crcs", "isoft", "spms", "tfsp", "pmp", "cbs", "cdip", "sip/sems", "fbi", "ilab", "hcmm", "wms\rf", "sfc", "palm"];
    for (var i = 0; i < userArr.length; i++) {
        if (userArr[i] == clostype) {
            return true;
        }
    }
    return false;
};

//显示帐号信息的提示信息
function showTitle(obj) {
    var type = $(obj).val().toLowerCase();
    var rowindex = $(obj).attr("id").substring("CloseType".length);
    var array = { "domainaccounttype": "拼音", "proxytype": "拼音", "lynctype": "拼音", "emailtype": "邮件地址", "notes": "拼音", "sap": "拼音", "erp": "拼音", "oos": "拼音" };

    for (var i in array) {
        if (i == type) {
            $("#span_info" + rowindex).html(array[i]);
            break;
        }
    }
}

//判断用户类型是否合法
function checkSamAccountUserType() {
    var samAccount = $("#SamAccount").val();
    var usetype = $("#UserType").val();
    if (samAccount == "") {
        return false;
    }
    if (usetype == "") {
        alert("请先选择用户类型!");
        $("#SamAccount").val("")
        return false;
    }
    if (samAccount.length < 4) {
        alert("销户人工号不存在，请确认!");
        $("#SamAccount").val("");
        return false;
    }
    if (usetype == "1") {
        if (isWXAccount(samAccount) || isAppSysAccont(samAccount)) {
            alert("被销户人工号的用户类型不是【正式员工销户】，请确认!");
            $("#SamAccount").val("");
            return false;
        }
        var re = /^[0-9]+$/;
        var objExp = new RegExp(re);
        if (!objExp.test(samAccount) || !samAccount.length == 5) {
            alert("请输入被销户人工号！");
            $("#SamAccount").val("");
            return false;
        }
    }
    else if (usetype == "0") {
        if (!isWXAccount(samAccount)) {
            alert("被销户人工号的用户类型不是【非正式员工销户】，请确认!");
            $("#SamAccount").val("");
            return false;
        }
    }

    return true;
}

////全选按钮
//function selectAll() {
//    if ($("#chk_selecAll").attr("checked")) {
//        $(".checkBoxSelect").each(function () {
//            $(this).blur(function(){disableSelect();});
//        }); 
//    }
//    else {
//        $(".checkBoxSelect").each(function () {
//            $(this).attr("checked", false);
//        }); 
//    }
//}

//用户类型为【非正式员工销户】时，审批人和申请人不能为同一人
function checkProxyManIsApproveMan() {
    var proxyman = $("#ProxyMan").val();
    var approveMan = $("#DeptManager").val();
    var usertype = $("#UserType").val();

    if (usertype == "0") {
        if (proxyman == approveMan) {
            alert("用户类型为【非正式员工销户】时，审批人和申请人不能为同一人，谢谢！");
            return false;
        }
    }
    return true;
}

//如果选择域帐号，emai，lync，notes帐号等不可以选择
function disableSelect(obj) {

    var id = $(obj).attr("id");
    var index = id.substring(id.length - 1);
    var curtype = $("#type" + index).val();
    var accountSelected = $("#samaccount" + index).val();

    if (curtype == "DomainAccountType") { //域帐号
        var vcount = $("#tbin tr").filter(".MyRow").size();
        for (var i = 0; i < vcount; i++) {
            if (i != index) {
                var type = $("#type" + i).val().toLowerCase();
                var samaccount = $("#samaccount" + i).val().toLowerCase();
                if (isSamAccountType(type)) {
                    if ($(obj).attr("checked")) {
                        //同一个人有可能有不能的帐号类型，这里只选择同一域帐号下的应用
                        if (accountSelected == samaccount) {
                            //把notes帐号选择上去
                            if (type == "notes") {
                                $("#chk_selecAll" + i).attr("checked", true);
                            }
                            else {
                                $("#chk_selecAll" + i).attr("checked", false); //不选择
                            }
                            $("#chk_selecAll" + i).attr("disabled", "disabled"); //不可选
                        }
                    }
                    else {
                        if (accountSelected == samaccount) {
                            $("#chk_selecAll" + i).removeAttr("disabled"); //可选
                            if ($("#chk_selecAll" + i).attr("checked")) {
                                $("#chk_selecAll" + i).attr("checked", false); //不选择
                            }
                        }
                    }
                }
            }
        }
    }
}

//显示域帐号名下的帐号
function showAccountes(data,id) {

    $("#"+id).empty();
    if (data != null && data.length > 0) {
        var tt = "<table  class=\"clearBottomBorder table table-hover table - striped\" style=\"border - bottom - width: 0px; margin - top: 0px;width: 100%;\"   cellspacing=\"0\" cellpadding=\"0\" id=\"tbin\">";
        tt += "<tr><td class=\"title\" style=\"width:4%;\">序号</td>";

        tt += "<td class=\"title\" style=\"width:13%;\">是否销户<br>（销户直接勾选即可）</td>";

        tt += "<td class=\"title\" style=\"width:20%;\">帐号类型</td>";
        tt += "<td class=\"title\" style=\"width:20%;\">帐号信息</td>";
        tt += "<td class=\"title\" style=\"width:20%;\">帐号管理员</td>";
        tt += "<td class=\"title\" style=\"width:20%;\">销户方式</td>";
        tt += "</tr>";
        var vcount = $("#tbin tr").filter(".MyRow").size();
        $.each(data, function (i, item) {
            var tr = "<tr class='MyRow'><td style=\"width:4%; \">" + (i + 1) + "</td>";
            i = vcount + i;
            //checkbox
            tr += "<td style=\"width:13%; align='center' \">";
            var index = "chk_selecAll" + i;
            //alert(item.appType);
            //if (item.accountType.toLowerCase() == "nc" || item.accountType.toLowerCase() == "citrix" || (item.appType != null && item.appType.toLowerCase() == "app")) {
            if ((item.appType != null && item.appType.toLowerCase() == "app")) {
                 tr += "<input id=" + index + " name=" + index + " disabled='disabled' type=\"checkbox\" value=\"true\" onchange='disableSelect(this)' class=\"checkBoxSelect\" />";
                 
            }
            else {
                tr += "<input id=" + index + " name=" + index + " type=\"checkbox\" value=\"true\" onchange='disableSelect(this)' idflag= " + item.id + " class=\"checkBoxSelect\" />";
            }
            tr += "<input name=" + index + " type=\"hidden\" value=\"false\" onchange='disableSelect(this)' class=\"checkBoxSelect\" />";
            tr += "</td>";

            tr += "<td style=\"width:20%;\"><span class=\"labeltext\">" + item.accountTypeName + "</span></td>";
            tr += "<td style=\"width:20%;\"><span class=\"labeltext\">" + item.accountMsg + "</span></td>";
            tr += "<td style=\"width:20%;\"><span class=\"labeltext\">" + item.adminName + "</span></td>";
            //var AppType = "";
            //    switch (item.AppType) {
            //        case "":
            //            AppType = "public";
            //            break;
            //    default:
            //}
            //tr += "<td style=\"width:20%;\"><span class=\"labeltext\">" + AppType + "</span></td>";
            tr += "<td style=\"width:20%;\" class=\"item2\">" + item.closeWay;

            //帐号类型
            //var accountTypeID =  "type"+i;
            tr += "<input type=\"hidden\" name='type" + i + "' id='type" + i + "' value=" + item.accountType + " />";
            tr += "<input type=\"hidden\" name='samaccount" + i + "' id=samaccount" + i + " value=" + item.id + " />";
            tr += "<input type=\"hidden\" name='msg" + i + "' id=msg" + i + " value='" + item.accountMsg + "' /></td>";
            tr += "</tr>";
            tt += tr;
        });

        tt += "</table>";

        $("#" + id).append(tt);
    }
    else {
        $("#" + id).append("<font size='2' color='red'>此帐号无对应的开户信息，无需申请销户.</font>");
    }
}

